import {defineStore} from "pinia";
import {HistoryRecordApi} from "../api/HistoryRecordApi.js";

export const useHistoryRecordStore = defineStore('useHistoryRecordStore', {

    state: () => ({
        rows: [
            // {
            //     id: "1",
            //     op: "123",
            //     user: "123",
            //     code: "123",
            //     name: "123",
            //     runTime:"2024-111",
            //     runContent: ""
            // }
        ],
        searchData: {
            erp: "",
            actionName: "",
            title: "",
            runTime: []
        },
        page: {
            totalCount: 0,
            pageSize: 10,
            currentPage: 1
        }
    }),
    actions: {

        async searchBtn() {

            let queryParam = {...this.searchData, pageNumber: this.page.currentPage, pageSize: this.page.pageSize};

            let result = await HistoryRecordApi.executeLogs(queryParam)
            this.rows = result.rows;
            this.page.totalCount = result.totalRows;
        },
        resetBtn() {
            this.searchData ={
                erp: "",
                actionName: "",
                title: "",
                runTime: []
            }
            this.page.totalCount = 0;
            this.page.currentPage = 1;
            this.page.pageSize = 10;

        },
        async pageChange(currentPage, pageSize) {
            let queryParam = {...this.searchData, pageNumber: currentPage, pageSize: pageSize};

            let result = await HistoryRecordApi.executeLogs(queryParam)
            this.rows = result.rows;
            this.page.totalCount = result.totalRows;
        },
        initPage() {
            this.rows =[];
            this.resetBtn();
        }
    }
})